import socket  # socket模块
import threading

def handler_sock(sock,addr):
    while True:
        print('the {IP} is send the connect request'.format(IP=IP))
        data = conn.recv(1024)  # 把接收的数据实例化
        print('CLIENT:{}'.format(data.decode()))
        server_send = input("SERVER:")
        conn.send(server_send.encode())


IP = '0.0.0.0'
PORT = 5000
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # 定义socket类型，网络通信，TCP
server.bind((IP, PORT))  # 套接字绑定的IP与端口
server.listen(1)  # 开始TCP监听
print('the server:{IP} is listend at :{PORT}'.format(IP=IP, PORT=PORT))
while True:
    conn, addr = server.accept()  # 接受TCP连接，并返回新的套接字与IP地址
    client_thread = threading.Thread(target=handler_sock,args=(conn,addr))
    client_thread.start()
    # server.close()
    # conn.close()  # 关闭连接
